package com.yfbao.horizon.schedule.tk.handler;

import com.github.houbb.sensitive.word.api.IWordDeny;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class DefaultWordDeny implements IWordDeny {
    @Override
    public List<String> deny() {
        return Arrays.asList( "天安门","飞翔","飘扬","飞翔各");
//        return Arrays.asList();

        //~`!@#$%^&*()_+-=[]{}\|:;'",.<>?/
//        return Arrays.asList("\\","/","~","`","'","\"","*");
//        return readResourceFileByLines("dict_1W.txt");
//        return readResourceFileByLines("dict_3000.txt");
//        return readResourceFileByLines("dict_1000.txt");
    }

    private List<String> readResourceFileByLines(String filename) {
        // 使用 ClassPathResource 创建 Resource 对象
        Resource resource = new ClassPathResource(filename);

        try {
            // 从 Resource 获取 InputStream
            InputStream inputStream = resource.getInputStream();

            // 使用 InputStreamReader 和 BufferedReader 逐行读取内容，暂不指定字符集，后期可能需指定字符集
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
            List<String> denyTextList = new ArrayList<>();
            String line;

            while ((line = reader.readLine()) != null) {
                denyTextList.add(line);
            }
            // 关闭资源
            reader.close();
            return denyTextList;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}
